package com.rd.student.jike.class4.wanghaixin;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        Member m1 = new Member("lihongming","jike",2,"牛逼",19);
        Member m2 = new Member("xuezhixin","jike",2,"很牛逼",20);
        Member m3 = new Member("wanghaixin","jike",4,"大牛",49);
        Member m4 = new Member("xiayinyin","jike",4,"可爱",46);
        Member m5 = new Member("wujunhao","jike",5,"大可爱",23);
        Member m6 = new Member("wangxiangyang","jike",5,"太可爱",40);
        list.add(m1);
        list.add(m2);
        list.add(m3);
        list.add(m4);
        list.add(m5);
        list.add(m6);
        Collections.sort(list);
        System.out.println(list);
        Collections.reverse(list);
        System.out.println(list);
    }

}

class Member implements Comparable{
    private String name;
    private String major;
    private int class1;
    private String discription;
    private int age;

    public Member() {

    }

    public Member(String name, String major, int class1, String discription, int age) {
        this.name = name;
        this.major = major;
        this.class1 = class1;
        this.discription = discription;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Member{" +
                "name='" + name + '\'' +
                ", major='" + major + '\'' +
                ", class1=" + class1 +
                ", discription='" + discription + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMajor() {
        return major;
    }

    public void setMajor(String major) {
        this.major = major;
    }

    public int getClass1() {
        return class1;
    }

    public void setClass1(int class1) {
        this.class1 = class1;
    }

    public String getDiscription() {
        return discription;
    }

    public void setDiscription(String discription) {
        this.discription = discription;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public int compareTo(Object o) {
        Member o1 = (Member)o;
        if(this.age > o1.age){
            return 1;
        }else if(this.age<o1.age){
            return -1;
        }else{
            return 0;
        }
    }
}

